package cn.zs.supply.common.utils;


import java.math.BigDecimal;
import java.util.Date;

/** 
 * 接口参数转换处理
 */
public class ParamDataParse {
	
	
	public final String buildCardModel(String carName) {
		String[] carNameArray = carName.split("-");
		return carNameArray[1] + "-" + carNameArray[2];
	}
	
	public final String converBusiStatus(Integer status) {
		if (status == -3) {
			return "D";
		} else if (status == -2) {
			return "C";
		} else if (status == 0) {
			return "A";
		}
		return " ";
	}
	
	public final String converHomeflag(Integer homestat) {
		if (homestat == 1) {
			return "1";
		} else if (homestat == 2) {
			return "1";
		} else if (homestat == 6) {
			return "1";
		}
		return "2";
	}
	
	public final String hasCorepayment(Integer userSize) {
		if (userSize != null && userSize > 1) {
			return "1";
		}
		return "0";
	}

	/**
	 * 转换风险筛查响应code
	 * @param code
	 * @return
	 */
	public final String converCode(String code) {
		if ("1".equals(code) || "2".equals(code)) {
			return "0";
		}
		return code;
	}
	
	/**
	 * 转换有效期 yyyy.MM.dd --> yyyy-MM-dd
	 * @param termTo
	 * @return
	 */
	public final String converRstatdate(String termTo) {
		if (StringUtil.isBlank(termTo)) {
			return " ";
		}
		return termTo.replace('.', '-');
	}
	/**
	 * 转换性别 
	 * @param sex
	 * @return
	 */
	public final String converSex(Integer sex) {
		if (sex == 0) {
			return "1";
		}
		return "2";
	}
	
	public final String generateRTimeless(String termTo) {
		if (StringUtil.isBlank(termTo)) {
			return " ";
		}
		return generateTimeless(termTo.replace('.', '-'));
	}
	
	public final String generateTimeless(String statdate) {
		if ("9999-12-30".equals(statdate)) {
			return "1";
		}
		return "0";
	}
	/**
	 * 转换yyyy-MM-dd
	 * @param date
	 * @return
	 */
	public final String formatYmdDate(Date date) {
		if (date == null) {
			return " ";
		}
		return DateUtil.formatDate(date, DateUtil.ymd_DATE_FORMAT);
	}
	/**
	 * 将字符串已-分割成数组，并返回角标为index的值
	 * @param carName
	 * @param index
	 * @return
	 */
	public final String stringtoArray(String carName, int index) {
		if (StringUtil.isBlank(carName)) {
			return " ";
		}
		String[] names = carName.split("-");
		return names[index];
	}
	/**
	 * 
	 * @param cocomReceiveAmt
	 * @return
	 */
	public final String converDecimal(BigDecimal decimal,int scale) {
		if (decimal != null) {
			return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
		}
		return " ";
	}
	
	public final String converDecimalZero(BigDecimal decimal,int scale) {
		if (decimal != null) {
			return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
		}
		return "0";
	}
	
	public final String converYearincome(BigDecimal monthIncomeMoney) {
		if (monthIncomeMoney != null) {
			return BigDecimalUtil.initMultiply(monthIncomeMoney, new BigDecimal(12)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";
		}
		return " ";
	}
	
	public final String IntToString(Integer apprel) {
		if (apprel != null) {
			return apprel.toString();
		}
		return " ";
	}
	
	
	public final String converUserType(Integer userType) {
		if (userType == 0) {
			return "0";
		} else {
			return "1";
		}
	}
	
	/**
	 * 通过身份证获取出生日期
	 * @param idCard
	 * @return
	 */
	public final String getBirthDate(String idCard){
		if (StringUtil.isNotBlank(idCard)) {
			return DateUtil.formatDate(IdcardUtils.getBirthDate(idCard), DateUtil.ymd_DATE_FORMAT);
		}
		return " ";
	}
	
	public final String converHouseArea(BigDecimal decimal){
		if (decimal != null) {
			BigDecimal setScale = decimal.setScale(0, BigDecimal.ROUND_HALF_UP);
			return BigDecimalUtil.initMultiply(setScale, new BigDecimal(100))+"";
		}
		return " ";
	} 
}
